package com.kyh.vo;

import java.util.HashMap;

import com.kyh.properties.ErrMsg;

public class A extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;
    
    public static int SUCCESS_CODE = 200;
    
    public int getCode() {
    	return Integer.parseInt(this.get("code").toString());
    }
    public String getMsg() {
    	return this.get("msg").toString();
    }

    public static A err() {
        A r = new A();
        r.put("code", 300);
        r.put("msg", ErrMsg.get(300));
        return r;
    }

    public static A err(int code) {
        A r = new A();
        r.put("code", 300);
        r.put("msg", ErrMsg.get(code));
        return r;
    }

    public static A err(String msg) {
        A r = new A();
        r.put("code", 300);
        r.put("msg", msg);
        return r;
    }
    
    public static A errLogin(String msg) {
        A r = new A();
        r.put("code", 402);
        r.put("msg", msg);
        return r;
    }

    public static A err(int code, String msg) {
        A r = new A();
        r.put("code", code);
        r.put("msg", msg);
        return r;
    }
    
    public static A suc() {
        A r = new A();
        r.put("code", SUCCESS_CODE);
        r.put("msg", ErrMsg.get(200));
        return r;
    }

    public static A suc(String msg) {
        A r = new A();
        r.put("code", SUCCESS_CODE);
        r.put("msg", msg);
        return r;
    }

    public static A suc(Object object) {
        A r = new A();
        r.put("code", SUCCESS_CODE);
        r.put("msg", ErrMsg.get(SUCCESS_CODE));
        r.put("data", object);
        return r;
    }

    public static A suc(String msg, Object object) {
        A r = new A();
        r.put("code", SUCCESS_CODE);
        r.put("msg", msg);
        r.put("data", object);
        return r;
    }

    @Override
    public A put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
